<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class games extends MY_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -  
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
	public function index($topic_id)
	{
        //var_dump($this->model_word->get(1));
        $words=$this->model_word->get_for_game($topic_id);
        
        $data['words']=$this->make_rand_data($words);
        
		$this->load_view('games/memory',$data);
        
	}
    
    private function make_rand_data($data){
        $list=array();
        $i=0;
        foreach($data as $d){
            $list[$i]=array('id'=>$d->id,'key'=>$d->key,'i'=>$i);
            $i++;
            $list[$i]=array('id'=>$d->id,'value'=>$d->value,'image'=>$d->image,'i'=>$i);
            $i++;
        }
        //var_dump($list);
        $list=$this->array_randsort($list);
        //var_dump($list);
        return $list;
    }
    
    private function array_randsort($array){
	   $list=array();
       while(count($array)>0 ){
            $temp=$array[array_rand($array)];
            //$temp
            //var_dump($temp);
            $t=$temp['i'];
            unset($array[$t]);
            array_push($list,$temp);
            //$i++;
       }
       return $list;
    }
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */